#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	int x;
	string s;
	cin >> x >> s;
	int ret = 0;
	int j = 0;
	for(int i = s.size() - 1; i >= 0; i--)
	{
		if(s[i] <= '9')
			ret += (s[i] - '0') * pow(x, j);
		else
			ret += (s[i] - 'A' + 10) * pow(x, j);
		j++;
	}
	cout << ret << endl;
	return 0;
}
